package com.cx.bank.service.impl;

import com.cx.bank.mapper.UserMapper;
import com.cx.bank.pojo.UserBean;
import com.cx.bank.service.LoginService;
import com.cx.bank.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("loginImpl")
public class LoginServiceImpl implements LoginService {
    @Autowired
    MD5 md5;
    @Autowired
    UserMapper userMapper;
    @Override
    public boolean login(String userName, String password) {
        UserBean userBean = userMapper.findUserByName(userName);
        if (userBean == null){
            return false;
        }
        if (userBean.getUserName().equals(userName)
                &&userBean.getPassword().equals(md5.getMD5(password))){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public void exitSystem(UserBean userBean) {
        UserBean user = userMapper.findUserByName(userBean.getUserName());
        userMapper.saveMoney(user);
    }


}
